package com.bnzj.cloud.oauth2resource.ext;

import com.bnzj.core.web.security.handler.AuthenticationParseFilter;
import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.jwt.Jwt;
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken;

/**
 * @ClassName JwtAuthenticationParserFilter
 * @Description JwtAuthenticationToken 解析
 * @Author
 * @Date 2020/3/3
 * @Version V1.0
 **/
public class JwtAuthenticationParserFilter implements AuthenticationParseFilter {

    @Override
    public String getUserName(Authentication authentication) {
        if(authentication instanceof JwtAuthenticationToken){
            return  ((Jwt)authentication.getCredentials()).getClaims().get("user_name").toString();
        }
        return null;
    }
}
